package com.andy.blog.admin.controller;

import com.andy.blog.admin.dto.login.HomeInfoDTO;
import com.andy.blog.admin.dto.login.LoginDTO;
import com.andy.blog.admin.service.LoginBusService;
import com.andy.blog.admin.service.SysPermissionBusService;
import com.andy.blog.common.reponse.GeneralResponseResult;
import com.andy.blog.dal.domain.vo.RouterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 登录验证
 * Created by andy on 2023-04-05 11:38
 */
@RestController
public class SysLoginController {

    @Resource
    private LoginBusService loginBusService;

    @Autowired
    private SysPermissionBusService sysPermissionBusService;


    /**
     * 登录方法
     *
     * @param loginDTO 登录信息
     * @return 结果
     */
    @PostMapping("/login")
    public GeneralResponseResult<Map<String, String>> login(@Validated @RequestBody LoginDTO loginDTO) {
        return GeneralResponseResult.success(loginBusService.login(loginDTO));
    }

    /**
     * 获取用户信息
     *
     * @return 用户信息
     */
    @GetMapping("getInfo")
    public GeneralResponseResult<Map<String, Object>> getInfo() {
        return GeneralResponseResult.success(sysPermissionBusService.getInfo());
    }

    /**
     * 获取路由信息
     *
     * @return 路由信息
     */
    @GetMapping("getRouters")
    public GeneralResponseResult<List<RouterVo>> getRouters() {
        return GeneralResponseResult.success(sysPermissionBusService.getRouters());
    }

    /**
     * 获取首页信息
     */
    @GetMapping("/getHome")
    public GeneralResponseResult<HomeInfoDTO> getHome() {
        return GeneralResponseResult.success(loginBusService.getHome());
    }
}
